define(['jquery', 'bootstrap', 'backend', 'table', 'form'], function ($, undefined, Backend, Table, Form) {

    var Controller = {
        index: function () {
            // 初始化表格参数配置
            Table.api.init({
                extend: {
                    index_url: 'user/user/index',
                    add_url: 'user/user/add',
                    edit_url: 'user/user/edit',
                    del_url: 'user/user/del',
                    multi_url: 'user/user/multi',
                    table: 'user',
                }
            });

            var table = $("#table");

            // 初始化表格
            table.bootstrapTable({
                url: $.fn.bootstrapTable.defaults.extend.index_url,
                pk: 'id',
                sortName: 'user.id',
                showExport:false,
                columns: [
                    [
                        {checkbox: true},
                        {field: 'id', title: __('Id'), sortable: true, operate: false},
                        {field: 'tj_nickname', title: '推荐人', operate: false},

                        {
                            field: 'pid',
                            title: '推荐人',
                            operate: '=',
                            table: table,
                            searchList: $.getJSON("user/user/searchlist"),
                            visible:false,
                            formatter: Table.api.formatter.search
                        },

                        {field: 'avatar', title: __('Avatar'), events: Table.api.events.image, formatter: Table.api.formatter.image, operate: false},
                        {field: 'nickname', title: __('Nickname'), operate: 'LIKE'},
                        {field: 'name', title: '真实姓名', operate: 'LIKE'},
                        {field: 'mobile', title: __('Mobile'), operate: 'LIKE'},
                        {field: 'shop_name', title: "车行名称", operate: 'LIKE'},
                        {field: 'city', title: "归属地区", operate: false},
                        {field: 'shop_address', title: "车行地址", operate: 'LIKE'},
                        {field: 'id_photo', title: "身份证正反面", events: Table.api.events.image, formatter: Table.api.formatter.image, operate: false},
                        {field: 'license', title: "营业执照", events: Table.api.events.image, formatter: Table.api.formatter.image, operate: false},
                        // {field: 'level_name', title: "会员级别", operate: false, sortable: true},
                        {field: 'vip_exp_time', title: '会员到期时间', formatter: Table.api.formatter.datetime, operate: 'RANGE', addclass: 'datetimerange', sortable: true},
                        {field: 'shop_status', title: "是否为车商", formatter: Table.api.formatter.status, searchList: {0:'普通用户',1:"车商",2:"车商被驳回"},sortable: true},
                        {field: 'money', title: '佣金', operate: 'BETWEEN', sortable: true},
                        // {field: 'margin', title: '保障金', operate: 'BETWEEN', sortable: true},
                        {field: 'car_old_num', title: '车源数量', operate: false},
                        {field: 'logintime', title: __('Logintime'), formatter: Table.api.formatter.datetime, operate: 'RANGE', addclass: 'datetimerange', sortable: true},
                        {field: 'loginip', title: __('Loginip'), operate: false, formatter: Table.api.formatter.search},
                        {field: 'jointime', title: __('Jointime'), formatter: Table.api.formatter.datetime, operate: 'RANGE', addclass: 'datetimerange', sortable: true},
                        {field: 'status', title: __('Status'), formatter: Table.api.formatter.status, searchList: {normal: __('Normal'), hidden: __('Hidden')}},
                        {field: 'operate', title: __('Operate'), table: table, events: Table.api.events.operate, formatter: Table.api.formatter.operate}
                    ]
                ]
            });

            // 为表格绑定事件
            Table.api.bindevent(table);
        },
        add: function () {
            Controller.api.bindevent();
        },
        edit: function () {
            Controller.api.bindevent();
        },
        api: {
            bindevent: function () {
                Form.api.bindevent($("form[role=form]"));
            }
        }
    };
    return Controller;
});